#ifndef PAINTWIDGET_H
#define PAINTWIDGET_H

#include "global.h"

#include "WhiteBoardFile.h"
#include "SelectPropertyWidget.h"

class PaintWidget : public QWidget
{
    Q_OBJECT
public:
    explicit PaintWidget(QWidget *parent = nullptr);
    ~PaintWidget();

    void ClearPaint();
    void RevocationSingleStep();
    void SaveData();
    void ReadFileData(const QString &);

    void setModelType(const PW::ModelType &);
    void setPloygonType(const PW::PLOYGONTYPE &);
    void setPen(const QPen &);
    void setBackgroundColor(const QColor &);

    WhiteBoardFile *GetFilePtr();

protected:
    void init();

    void paintEvent(QPaintEvent *);
    void mousePressEvent(QMouseEvent *);
    void mouseReleaseEvent(QMouseEvent *);
    void mouseMoveEvent(QMouseEvent *);

    void paintRectangle(QPainter *, PW::PROPERTYDATA *);
    void paintEllipose(QPainter *, PW::PROPERTYDATA *);
    bool IsSelectPolygon(const QPoint &,PW::PROPERTYDATA &);

protected slots:
    void deletePloygon(const int &);

signals:
    void changeBackgroundColor(const QColor &);
    void LeftButtonPressed();
    void setNormalEraser();

private:
    bool MouseLeftIsPressed;
    unsigned int PaintStep;                             // 绘图步骤
    int SelectCnt;                                      // 选中的序号
    int ReceiveSelectCnt;                               // 记录清前选中的序号
    QPoint MouseLeftPressedPoint;
    QColor BackgroundColor;

    WhiteBoardFile *whiteBoardFile;                     // 文件操作
    QMap<unsigned int,PW::PROPERTYDATA> PaintData;      // QMap<一笔绘图编号,QPair<线类型,数据>>
    SelectPropertyWidget *selectPropertyWidget;         // 选中编辑小窗口

    QPen pen;
    PW::ModelType mt;
    PW::PLOYGONTYPE pt;

    QList<QPoint> TmpPoints;                             // 临时存储点
};

#endif // PAINTWIDGET_H
